var page = Forguncy.Page; //当前页面
function getD() {
	var d = page.getCell("d").getValue(); //账期  25
	var retDate = page.getCell("retDate");

	var date = new Date(); //31
	if (d <= date.getDate()) {
		date.setDate(d)
		date.setMonth(date.getMonth() + 1)
	}
	date.setDate(d)

	retDate.setValue(date)
}



function reload() {
	var listview = page.getListView("表格1");
	var count = listview.getRowCount();
	for (var i = 0; i < count; i++) {

		var d = listview.getValue(i, "zhangqi")
		//var retDate = page.getCell("retDate");

		var date = new Date();
		if (d <= date.getDate()) {
			date.setDate(d)
			date.setMonth(date.getMonth() + 1)
		}
		date.setDate(d)
		date.setHours(0)
		date.setMinutes(0)
		date.setSeconds(0)


		//retDate.setValue(date)
		listview.setValue(i, "dage", date);


	}



}

function pro_type(table) {
	//定义事件处理函数
	var change = function(arg, arg1) {
		var col = 12;
		var Row = arg1.CellRanges[0].Row
		var Column = arg1.CellRanges[0].Column

		var kuan = page.getCell("kuan").getValue();
		var p = page.getCell("xishu").getValue();
		var hou1 = page.getCell("houe1").getValue();
		var guhualiang = page.getCell("guhualiang").getValue() / 100;

		var jiaoshui = page.getCell("jiaoshui").getValue();
		var rongji = page.getCell("rongji").getValue();
		var guhuaji = page.getCell("guhuaji").getValue();

		if (Column == col) {
			var type = listview.getValue(Row, Column)
			var hou = listview.getValue(Row, 4)
			var kuan1 = listview.getValue(Row, 8)
			var danwei = listview.getValue(Row, 9)
			var jieguo = 0
			switch (type) {

				case "膜材":
				case "基材":
					if (danwei == 'kg') {
						// console.log(kuan1)
						// console.log(kuan)
						// console.log(p)
						// console.log(hou)

						jieguo = (kuan1 / kuan) * p * hou / 1000
					} else {
						jieguo = kuan1 / kuan
					}

					break;
				case "胶水":
					jieguo = hou1 / guhualiang / 1000
					break;
				case "固化剂":
					jieguo = (hou1 * guhuaji) / (guhualiang * jiaoshui) / 1000
					break;
				case "溶剂":
					jieguo = (hou1 * rongji) / (guhualiang * jiaoshui) / 1000
					break;
			}
			listview.setValue(Row, col + 1, jieguo)
		}

	}
	//获取当前页面
	var page = Forguncy.Page;
	//获取表格对象
	var listview = page.getListView(table);
	//绑定表格的事件
	listview.bind("valueChanged", change);
}


function removeFun() {
	this.name = 'removeString';
	this.maxArgs = 2;
	this.minArgs = 1;
}
removeFun.prototype = new GC.Spread.CalcEngine.Functions.Function();
removeFun.prototype.evaluate = function(str) {
	var ar2 = str.split(",");
	var array = new Array();
	var j = 0
	for (var i = 0; i < ar2.length; i++) {
		if ((array == "" || array.toString().match(new RegExp(ar2[i], "g")) == null) && ar2[i] != "") {
			array[j] = ar2[i];
			array.sort();
			j++;
		}
	}
	return array.toString().replace(/,/g, ",");
}

GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("removeString", new removeFun()); // JavaScript source code
